import request from "@/utils/request";
const defaultApi = (apiName) => {
    return {
        list: (params) => request.get(`/${apiName}/list`, { params }),
        simpleList: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    login: (data) => request.post('/user/login', data),
    menu: defaultApi('menu'),
    role: defaultApi('role'),
    user: {
        ...defaultApi('user'),
        getUserInfo: (userId) => request.get(`/user/getUserInfo`, { params: { userId }}),
        getUserRoles: (userId) => request.get(`/user/getUserRoles`, { params: { userId }}),
        updateUserRoles: (data) => request.post(`/user/updateUserRoles`, data),
    },
    member: defaultApi('member'),

    // 物流管理系统相关API
    expressOutlet: defaultApi('expressOutlet'),
    warehouse: defaultApi('warehouse'),
    logisticsCompany: defaultApi('logisticsCompany'),
    itemCategory: defaultApi('itemCategory'),
    item: defaultApi('item'),
    insuranceCompany: defaultApi('insuranceCompany'),
    insuranceCoverage: defaultApi('insuranceCoverage'),

    // 订单管理相关API
    expressOrder: {
        ...defaultApi('expressOrder'),
        createOrder: (data) => request.post('/expressOrder/createOrder', data),
        updateStatus: (data) => request.post('/expressOrder/updateStatus', data),
        getUserOrders: (params) => request.get('/expressOrder/getUserOrders', { params }),
        getTrackInfo: (params) => request.get('/expressOrder/getTrackInfo', { params }),
    },

    // 物流轨迹相关API
    logisticsTrack: {
        ...defaultApi('logisticsTrack'),
        addTrack: (data) => request.post('/logisticsTrack/addTrack', data),
    },

    // 系统公告相关API
    announcement: {
        ...defaultApi('announcement'),
        getActiveAnnouncements: () => request.get('/announcement/getActiveAnnouncements'),
    },
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
